<?xml version="1.0" encoding="utf-8"?>
<!--
  ============================
  Default stylesheets for PSIs
  ============================
  
  Author:  Lars Heuer <heuer[at]semagia.com>
  License: Donated to the Public Domain
  Version: $Rev: 26 $ $Date: 2010-09-14 18:29:59 +0000 (Tue, 14 Sep 2010) $
-->
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:tm="http://psi.ontopia.net/xml/tm-xml/"
                xmlns:iso="http://psi.topicmaps.org/iso13250/model/"
                xmlns:op="http://psi.ontopedia.net/"
                xmlns:dc="http://purl.org/dc/elements/1.1/"
                xmlns:dct="http://purl.org/dc/terms/"
                xmlns:tmcl="http://psi.topicmaps.org/tmcl/"
                xmlns="http://www.w3.org/1999/xhtml">

  <xsl:output method="xml" media-type="text/html" encoding="utf-8" indent="yes"/>

  <xsl:template match="/">
    <!-- Select the topic that provides the PSI -->
    <xsl:variable name="psi-topic" select="/*/*[namespace-uri() != 'http://psi.ontopedia.net' and local-name() != 'PSI'][dc:description]"/>
    <!--** Creates the HTML envelope -->
    <html>
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title><xsl:value-of select="$psi-topic/iso:topic-name[not(@reifier)][not(@scope)]/tm:value"/></title>
        <style type="text/css">* { margin:0; padding: 0; } body {margin-top:50px; margin-left: 10%;font-size: 100.01%; font-family: Arial, Helvetica; sans-serif; color: #000; background-color: #fff;} h1 { padding-bottom: 30px; } tr {color: #4d4d4d;} td.caption { text-align: right;  padding-right: 10px;} td.caption:after {content: ":"; } tr.psi td:first-child, tr.descr td:first-child {font-weight: bold;} tr.psi, tr.descr{font-size: 120%;} tr.psi, tr.descr td{color: #000;} tr.descr td {padding-bottom: 40px;} a { text-decoration: None; color: blue;} a:hover { text-decoration: underline; color: blue; background-color: yellow; } tr.publisher a, tr.usage a { color: black; }</style>
        <!-- You may a link to a CSS do enhance the basic design: -->
        <!-- <link rel="stylesheet" type="text/css" href="/styles/psi.css"/> -->
      </head>
      <body>
        <xsl:apply-templates select="$psi-topic"/>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="*">
    <!--** Matches the PSI topic -->
    <h1>PSI for <xsl:value-of select="iso:topic-name[not(@reifier)][not(@scope)]/tm:value"/></h1>
    <table>
      <tr class="psi"><td class="caption">Published Subject Indicator</td><td><a href="{tm:identifier}"><xsl:value-of select="tm:identifier"/></a></td></tr>
      <tr class="descr"><td class="caption">Description</td><td><xsl:value-of select="dc:description"/></td></tr>
      <xsl:if test="namespace-uri() = 'http://psi.topicmaps.org/tmcl/'">
        <tr class="usage"><td class="caption">Usage</td><td><a href="{concat(namespace-uri(), local-name())}"><xsl:value-of select="concat(substring-before(local-name(), '-'), ' ', substring-after(local-name(), '-'))"/></a></td></tr>
      </xsl:if>
      <xsl:apply-templates select="/*/op:PSI"/>
    </table>
  </xsl:template>

  <xsl:template match="op:PSI">
    <!--** Provides some information about the PSI -->
    <!-- Opera and maybe other browsers do not support the str:split function of EXSLT. This is a work around -->
    <xsl:variable name="status-name"  select="substring-before(substring-after(op:psi_has_status/@topicref, ':'), '_')"/>
    <tr class="status"><td class="caption">Status</td>
      <td>
        <xsl:choose>
          <xsl:when test="$status-name = 'Experimental' or $status-name = 'Stable'"><xsl:value-of select="$status-name"/></xsl:when>
          <xsl:otherwise>unknown</xsl:otherwise>
        </xsl:choose>
      </td>
    </tr>
    <xsl:variable name="publisher-iri" select="dc:publisher/@topicref"/>
    <xsl:variable name="publisher" select="/*/tm:topic[not(dc:description)][tm:identifier/text() = $publisher-iri]"/>
    <tr class="publisher"><td class="caption">Publisher</td>
    <td>
      <xsl:choose>
        <!-- Add a hyperlink iff the publisher's subject identifier uses the http(s) or mailto scheme -->
        <xsl:when test="starts-with($publisher/tm:identifier, 'http') or starts-with($publisher/tm:identifier, 'mailto')">
          <a href="{$publisher/tm:identifier}"><xsl:value-of select="$publisher/iso:topic-name/tm:value"/></a>
        </xsl:when>
        <xsl:otherwise><xsl:value-of select="$publisher/iso:topic-name/tm:value"/></xsl:otherwise>
      </xsl:choose>
    </td></tr>
    <tr class="creation_date"><td class="caption">Created</td><td><xsl:value-of select="dct:created"/></td></tr>
    <xsl:if test="dct:modified and dct:modified/text() != dct:created/text()">
      <tr class="modification_date"><td class="caption">Updated</td><td><xsl:value-of select="dct:modified"/></td></tr>
    </xsl:if>
  </xsl:template>

</xsl:stylesheet>
